#pragma once

class Mesh
{
	ID3DXMesh* m_mesh;
	IDirect3DDevice9* m_device;
	ui8 m_type;
	void* m_pData;
	Mutex m_lock;
public:
	Mesh();
	~Mesh();
	bool Load(void* pVertices, VertexFMT format, ui32 numVertices, ui32 numPrims, WORD* pIndices = 0, ui32 numIndices = 0);
	NOINLINE void Draw();
	bool Intersect(const D3DXVECTOR3& pt1, const D3DXVECTOR3& dir, FLOAT& distToPt1);
	ui8 GetType() { return m_type; }
	void SetType(ui8 type) { m_type = type; }
	void* GetData() { return m_pData; }
	void SetData(void* data) { m_pData = data; }
	void Scale(float x, float y, float z);
	void Lock(void** ppOut)
	{
		m_lock.Acquire();
		m_mesh->LockVertexBuffer(D3DLOCK_DISCARD, ppOut);
	}

	void Unlock()
	{
		m_mesh->UnlockVertexBuffer();
		m_lock.Release();
	}

	void BeforeReset()
	{
		//while(m_mesh && m_mesh->Release());
	}
};